跳到主要内容

C++ 读取数量不定的输入数据

while (std::cin >> value)  
sum += value;

当我们执行表达式 std::cin >> value 时,它从标准输入读取一个数并返回 cin 对象,如果遇到文件结束符则变为无效。